#include <iostream>
using namespace std;

class A
{
public:
    virtual ~A() {} // 添加虚析构函数，使 A 成为多态类
    int a = 10;
};

class B : public A
{
public:
    int b = 100;
};

int main()
{
    A * pa = new B;
    B * pb = dynamic_cast<B*>(pa);

    if (pb != nullptr) {
        cout << "Conversion successful" << endl;
        // 可以安全地使用 pb
    } else {
        cout << "Conversion failed" << endl;
    }

    delete pa; // 释放内存
    return 0;
}
